Computer Graphics - Viewing Transformation include the following topics: View / Camera Transformation and Projection Transformation.
CG-Viewing Transformation
View Transformation
- Define the camera first
- Position
- Look-at / gaze direction
- Up direction
(assuming perpendicular to look-at)
- Position
Key observation
If the camera and all objects move together, the “photo” will be the same.
How about that we always transform the camera to
- The origin, up at
, look at - And transform the objects along with the camera
in math? - Translates
to origin - Rotates
to - Rotates
to - Rotates
to - Difficult to write!
- Translates
in math? - Let's write
- Translate
to origin: - Rotate
to , to , to
- Translate
- Consider its inverse rotation:
- Let's write
Also Known as ModelView Transformation
Projection Transformation
Orthographic Projection
A simple way of understanding
- Camera located at origin, looking at
, up at - Drop
coordinate - Translate and scale the resulting rectangle to
- Camera located at origin, looking at
In general
- We want to map a cuboid
to the "canonical" (正则, 规范, 标准) cube.
- We want to map a cuboid
Transformation matrix
- Translate (center to origin) first, then scale (length/width/height to 2)
Perspective Projection
- How to do perspective projection
- First "squish" the frustum into a cuboid (
) ( ) - Do orthographic projection (
, already known!)
- First "squish" the frustum into a cuboid (
In order to find a transformation
- Find the relationship between transformed points (
)
and the original points ():
- Find the relationship between transformed points (
- In homogeneous coordinates,
- So the "squish" (persp to ortho) projection does this
- Already good enough to figure out part of
:
Observation: the third row is responsible for
- Any point on the near plane will not change
- Any point’s
on the far plane will not change
Any point on the near plane will not change
- So the third row must be of the form
- Any point’s
on the far plane will not change
- Solve for
and :
- Finally, every entry in
is known!
- What’s next?
- Perform orthographic projection (
) to finish. - Combine transformations:
- Perform orthographic projection (
Vertical field-of-view (fovY)
How to convert from fovY and aspect to